var e = require("@babel/runtime/helpers/typeof");
App({
    WWW: "https://love.whbcrs.com", _ZEAI: {}, _VIP: {}, get_config: function (e) {
        var n = this;
        return new Promise((function (t, o) {
            var i = wx.getStorageSync("COOK_ZEAI");
            n.empty(i.color) || n.empty(i.siteName) || n.empty(i.ifps) ? n.ajax({
                url: "get_config.php",
                data: {f: e, ver: 10},
                success: function (o) {
                    "_ZEAI" == e ? (n._ZEAI = o, wx.setStorageSync("COOK_ZEAI", {
                        ifps: o.ifps,
                        siteName: o.siteName,
                        color: o.color,
                        loveb: o.loveb,
                        cache_str: o.cache_str,
                        tabbar: o.tabbar
                    })) : "_VIP" == e && (n._VIP = o), t(o)
                }
            }) : (n._ZEAI = i, t(i))
        }))
    }, onLaunch: function () {
        var e = wx.getUpdateManager();
        e && (e.onCheckForUpdate((function (e) {
        })), e.onUpdateReady((function () {
            wx.showModal({
                title: "更新提示", content: "新版本已经准备好，是否重启应用？", success: function (n) {
                    n.confirm && e.applyUpdate()
                }
            })
        })), e.onUpdateFailed((function () {
        }))), this.get_config("_ZEAI"), this.get_openid()
    }, get_openid: function () {
        var e = this;
        return new Promise((function (n, t) {
            var o = wx.getStorageSync("COOK_U"), i = !1;
            if (wx.getSystemInfo({
                success: function (e) {
                    if ("singlePage" == e.mode) return i = !0, "function" == typeof n && n(o.openid), !0
                }
            }), i) return "function" == typeof n && n(o.openid), !0;
            e.empty(o.openid) || e.empty(o) ? wx.login({
                success: function (t) {
                    e.ajax({
                        url: "get_openid.php", data: {code: t.code}, success: function (e) {
                            wx.setStorageSync("COOK_U", {
                                openid: e.U.openid,
                                unionid: e.U.unionid,
                                session_key: e.U.session_key
                            }), "function" == typeof n && n(e.U.openid)
                        }
                    })
                }
            }) : "function" == typeof n && n(o.openid)
        }))
    }, chklogin: function (e) {
        var n = this;
        return new Promise((function (e, t) {
            var o = wx.getStorageSync("COOK_U");
            if (!n.empty(o.openid) && (1 == o.flag || -2 == o.flag)) return e(!0), !1;
            var i = !1;
            if (wx.getSystemInfo({
                success: function (n) {
                    if ("singlePage" == n.mode) return i = !0, wx.setStorageSync("COOK_U", {
                        id: 0,
                        openid: "",
                        unionid: "",
                        flag: 0,
                        kind: 1
                    }), "function" == typeof e && e(o.openid), !0
                }
            }), i) return "function" == typeof e && e(o.openid), !0;
            wx.showLoading({title: "玩命加载中", mask: !0}), wx.login({
                success: function (t) {
                    n.ajax({
                        url: "login.php", data: {code: t.code, submitok: "chklogin"}, success: function (n) {
                            switch (n.flag) {
                                case"reged":
                                    switch (wx.setStorageSync("COOK_U", {
                                        id: n.U.id,
                                        openid: n.U.openid,
                                        unionid: n.U.unionid,
                                        flag: n.U.flag,
                                        kind: n.U.kind
                                    }), parseInt(n.U.flag)) {
                                        case 1:
                                        case-2:
                                            e(!0);
                                            break;
                                        case-1:
                                            wx.showModal({
                                                content: "您的帐号ID：" + n.U.id + "已被锁定或注销，请联系管理员",
                                                confirmText: "朕知道了",
                                                showCancel: !1,
                                                success: function (e) {
                                                    wx.exitMiniProgram({
                                                        success: function (e) {
                                                        }
                                                    })
                                                }
                                            });
                                            break;
                                        case 0:
                                            wx.showModal({
                                                content: "您已注册成功，请等待我们审核",
                                                confirmText: "朕知道了",
                                                showCancel: !1,
                                                success: function (e) {
                                                }
                                            });
                                            break;
                                        case 2:
                                            wx.navigateTo({url: "/pages/reg/reg"})
                                    }
                                    break;
                                case"noreg":
                                    e(!1);
                                    break;
                                default:
                                    wx.showModal({
                                        content: n.msg,
                                        confirmText: "朕知道了",
                                        showCancel: !1,
                                        success: function (e) {
                                        }
                                    })
                            }
                            wx.hideLoading()
                        }
                    })
                }
            })
        }))
    }, empty: function (e) {
        return "" == e || "NAN" == e || 0 == e || null == e || "null" == e || null == e || "undefined" === e || "undefined" == e
    }, ifmob: function (e) {
        return !!/^1[3,4,5,6,7,8,9]\d{9}$/.test(e)
    }, ifweixin: function (e) {
        return !(!/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/.test(e) && !this.ifmob(e))
    }, ajax: function (e) {
        var n = this;
        e.method || e.method, wx.request({
            url: n.WWW + "/api/wxxcx/" + e.url,
            method: e.method,
            data: e.data,
            header: {"content-type": "application/json"},
            success: function (t) {
                t.statusCode.toString().startsWith("2") ? e.success && e.success(n.jsoneval(t.data)) : wx.showToast({
                    title: "抱歉，请求出错",
                    icon: "none",
                    mask: !0
                })
            },
            fail: function (e) {
                wx.showToast({title: "抱歉，刚刚网络开了个小差", icon: "none", mask: !0}), wx.hideLoading()
            }
        })
    }, pay: function (e) {
        var n = wx.getStorageSync("COOK_U"), t = e.data, o = this;
        t.openid = n.openid, this.ajax({
            url: "pay.php", data: t, success: function (n) {
                if (1 == n.flag) {
                    var t = n.paydata;
                    wx.requestPayment({
                        timeStamp: t.timeStamp,
                        nonceStr: t.nonceStr,
                        package: t.package,
                        signType: "MD5",
                        paySign: t.paySign,
                        success: function (t) {
                            var o = t.errMsg;
                            "requestPayment:ok" == (o = o.replace(/\s+/g, "")) ? "function" == typeof e.success ? e.success(n) : (wx.showToast({
                                title: "支付成功！",
                                icon: "success",
                                mask: !0,
                                duration: 2e3
                            }), setTimeout((function () {
                                wx.navigateBack()
                            }), 2e3)) : "function" == typeof e.fail ? e.fail(n) : wx.showToast({
                                title: "支付失败！",
                                icon: "none",
                                mask: !0,
                                duration: 2e3
                            })
                        },
                        fail: function (n) {
                            "function" == typeof e.fail ? e.fail(n) : wx.navigateBack()
                        },
                        complete: function (e) {
                        }
                    })
                } else "function" == typeof e.fail ? e.fail(n) : wx.showModal({
                    content: n.msg,
                    confirmColor: o._ZEAI.color,
                    confirmText: "朕知道了",
                    showCancel: !1,
                    success: function (e) {
                    }
                })
            }
        })
    }, jsoneval: function (n) {
        return "object" != e(n) ? (n = n.replace(/\ufeff/g, ""), JSON.parse(n)) : n
    }, get_navigationBarTopHeight: function (e) {
        wx.getSystemInfo({
            success: function (n) {
                var t = n.statusBarHeight, o = wx.getMenuButtonBoundingClientRect(), i = 2 * (o.top - t) + o.height,
                    a = getCurrentPages();
                e.setData({nTop: n.statusBarHeight, nHeight: i, nTH: n.statusBarHeight + i, pages: a})
            }
        })
    }, get_pages: function (e) {
        var n = getCurrentPages();
        e.setData({pages: n})
    }, ifint: function (e) {
        return !!/^[0-9]*[1-9][0-9]*$/.test(e)
    }, getPhoneNumber: function (e) {
        var n = this, t = e.e, o = n.ifint(e.tguid) ? e.tguid : 0, i = n.ifint(e.admid) ? e.admid : 0;
        wx.login({
            success: function (a) {
                wx.request({
                    url: n.WWW + "/api/wxxcx/get_openid.php", data: {code: a.code}, success: function (a) {
                        a = n.jsoneval(a.data);
                        wx.getStorageSync("COOK_U");
                        wx.request({
                            url: n.WWW + "/api/wxxcx/get_mob.php",
                            data: {
                                session_key: encodeURIComponent(a.U.session_key),
                                encryptedData: encodeURIComponent(t.detail.encryptedData),
                                iv: encodeURIComponent(t.detail.iv),
                                openid: a.U.openid,
                                submitok: e.submitok,
                                tguid: o,
                                admid: i
                            },
                            success: function (t) {
                                t = n.jsoneval(t.data), console.log({
                                    submitok: e.submitok,
                                    tguid: o,
                                    admid: i
                                }), "navigateTo" == e.urlkind ? wx.navigateTo({url: e.url}) : wx.reLaunch({url: e.url})
                            },
                            fail: function (e) {
                                wx.showModal({content: e, showCancel: !1})
                            }
                        })
                    }
                })
            }
        })
    }, openSetting: function (e, n) {
        wx.requestSubscribeMessage({
            tmplIds: e, success: function (e) {
                "function" == typeof n && n(e)
            }, fail: function (e) {
                console.log(e)
            }
        })
    }, globalData: {aid: 0, U: [], hn_par: {}, index_par: {}, checkboxMaxNum: 8}
});